package cn.tedu.submarine;

import javax.swing.ImageIcon;

/**
 * 战舰类
 */
public class Battleship extends SeaObject {
    public static final int LIFE = 5;//战舰默认生命值
    public static final int FIREONE = 0;//战舰1倍火力状态
    public static final int FIRETWO = 1;//战舰3倍火力状态
    private int fire = FIREONE;//战舰火力默认1倍

    public static final int ONESHIP = 0;//魔女1标记
    public static final int TWOSHIP = 1;//魔女2标记
    private int marker = ONESHIP;//战舰默认1号
    private int witchOneIndex = 0;//魔女1组图下标
    private int witchTwoIndex = 0;//魔女2组图下标

    private int coinNumber;//金币数

    public Battleship(int width, int hight, int x, int marker) {//战舰属性初始化
        super(width, hight, x, 200, 16, LIFE);
        coinNumber = 0;
        this.marker = marker;//赋战舰编号
    }

    public int getCoinNumber() {//获取金币数
        return coinNumber;
    }

    public void setCoinNumber() {//金币数减30
        this.coinNumber -= 30;
    }

    public int getMarker() {//获取战舰编号
        return marker;
    }

    public void move() {
    }

    public void toMove(int x) {//根据鼠标x坐标改变战舰x坐标
        setX(x - getWidth() / 2);
        if (getX() <= 0) {//战舰越界判定
            setX(0);
        }
        if (getX() >= World.WIDTH - getWidth()) {
            setX(World.WIDTH - getWidth());
        }
    }

    public Bomb[] shootBomb() {//获得炸弹
        Bomb[] bo;
        if (fire == FIRETWO) {//3倍火力时生成3倍炸弹
            bo = new Bomb[3];
            for (int i = 0; i < bo.length; i++) {
                bo[i] = new Bomb(this.getX(), this.getY() + getHight() / 2, i, this.marker);
            }
        } else {//1倍火力时生成1倍炸弹
            bo = new Bomb[1];
            bo[0] = new Bomb(this.getX(), this.getY() + getHight() / 2, 1, this.marker);
        }
        return bo;
    }

    public void moveleft() {//战舰左移动方法
        setX(getX() - getSpeed());
        if (getX()<=0){
            setX(0);
        }
    }

    public void moveRight() {//战舰右移动方法
        setX(getX() + getSpeed());
        if (getX()>=World.WIDTH-getWidth()){
            setX(World.WIDTH-getWidth());
        }
    }


    public void addLife(int num) {//战舰加命方法
        setLife(getLife() + num);
    }

    public void addCoin(int num) {//战舰加金币方法
        coinNumber += num;
    }

    public void changeFireTwo() {//战舰火力改为3倍
        fire = FIRETWO;
    }

    public void changeFireOne() {//战舰火力改为1倍
        fire = FIREONE;
    }

    public int getFire() {//获取战舰火力值
        return fire;
    }



    int indexOne = 0;
    int indexTwo = 0;
    int moIndex = 0;
    int boomIndex = 0;
    public ImageIcon getImage() {//画魔女
        if (isLive()) {
            if (marker==ONESHIP) {
                indexOne++;
                if (indexOne % 10 == 0) {
                    return Images.witchone[witchOneIndex++%8];
                } else {
                    return Images.witchone[witchOneIndex%8];
                }
            } else{
                indexTwo++;
                if (indexTwo % 10 == 0) {
                    return Images.witchtwo[witchTwoIndex++%6];
                } else {
                    return Images.witchtwo[witchTwoIndex%6];
                }
            }
        }else{
            if (++moIndex % 10 == 0) {
                boomIndex++;
                if (boomIndex==10){
                    setState(REMOVE);
                    return Images.boommap[boomIndex-1];
                }
                return Images.boommap[boomIndex];
            }else {
                return Images.boommap[boomIndex];
            }
        }

    }
}
